#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
检查数据库中医生的详细信息
"""
import pymysql

# 数据库配置
DB_CONFIG = {
    'host': 'localhost',
    'user': 'flask_dev',
    'password': 'dev123456',
    'database': 'flask_local',
    'charset': 'utf8mb4'
}

def check_doctor_info():
    """检查医生信息"""
    try:
        conn = pymysql.connect(**DB_CONFIG)
        cursor = conn.cursor(pymysql.cursors.DictCursor)
        
        # 1. 查询所有医生用户
        print("[INFO] 查询所有医生用户...")
        print("=" * 80)
        
        cursor.execute("""
            SELECT id, openid, wechat_name, phone, role, status, create_time 
            FROM user 
            WHERE role = 1
            ORDER BY create_time DESC
        """)
        doctors = cursor.fetchall()
        
        if not doctors:
            print("[WARNING] 数据库中没有找到医生用户（role=1）")
            return
        
        print(f"[OK] 找到 {len(doctors)} 个医生用户:\n")
        
        for i, doctor in enumerate(doctors, 1):
            print(f"医生 #{i}:")
            print(f"  用户ID: {doctor['id']}")
            print(f"  OpenID: {doctor['openid']}")
            print(f"  微信昵称: {doctor['wechat_name']}")
            print(f"  手机号: {doctor['phone']}")
            print(f"  状态: {'正常' if doctor['status'] == 1 else '禁用'}")
            print(f"  注册时间: {doctor['create_time']}")
            
            # 2. 查询该医生的详细信息（user_doctor表）
            cursor.execute("""
                SELECT id, user_id, real_name, hospital, department, position, create_time
                FROM user_doctor
                WHERE user_id = %s
            """, (doctor['id'],))
            doctor_detail = cursor.fetchone()
            
            if doctor_detail:
                print(f"  [OK] 医生详细信息已完善:")
                print(f"    真实姓名: {doctor_detail['real_name']}")
                print(f"    医院: {doctor_detail['hospital']}")
                print(f"    科室: {doctor_detail['department']}")
                print(f"    职位: {doctor_detail['position']}")
                print(f"    完善时间: {doctor_detail['create_time']}")
            else:
                print(f"  [ERROR] 未找到医生详细信息（user_doctor表中无记录）")
                print(f"  [建议] 需要调用 POST /api/v1/users/doctor 接口完善医生信息")
            
            print("-" * 80)
        
        cursor.close()
        conn.close()
        
    except pymysql.Error as e:
        print(f"[ERROR] 数据库错误: {e}")
    except Exception as e:
        print(f"[ERROR] 执行失败: {e}")

if __name__ == '__main__':
    check_doctor_info()


